<!-- GetRecommendNotesPage.vue -->
<template>
  <div class="container">
    <div class="input-wrapper">
      <span class="input-label">推荐索引</span>
      <el-input v-model="recommendInput" placeholder="请输入推荐索引"  />
      <el-button type="primary" @click="handleRecommendClick">抓取数据</el-button>
    </div>
    <xhs-table-vue :table-data="recommendTableData" :loading="recommendLoading" ></xhs-table-vue>
  </div>
</template>

<script setup>
import { getIndexData } from '@/api/xhs'
import { ref } from 'vue'
import xhsTableVue from '@/components/Table/XhsTableVue.vue'

const recommendLoading = ref(false)
const recommendInput = ref('')
const recommendTableData = ref([])

const handleRecommendClick = async () => {
  try {
    // 请求的时候如果表格中有数据，那么就清空原来的数据
    if(recommendTableData.value.length > 0){
      recommendTableData.value = []

    }
    recommendLoading.value = true
    const result = await getIndexData(recommendInput.value)
    const data = result['data']
    // console.log(data)
    recommendTableData.value = data
  } catch (error) {
    console.log(error)
  } finally {
    recommendLoading.value = false
  }
}
</script>

<style scoped>
.container {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 10px;
}
.input-wrapper {
  width: fit-content;
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
}
.input-label {
  width: fit-content;
  padding: 5px;
  font-size: 16px;
  display: flex;
  align-items: center;
  white-space: nowrap;
}
</style>
